var orderVm;
var pageIndex=0;
var pageSize=50;
var getDataListHttp;
var openId='';
var pageNum = 50;
$(function(){
    //openId = getParam('openId');
    var openIdLocal = window.localStorage.getItem("openId");
    if (openIdLocal != null && openIdLocal != undefined && openIdLocal != '') {
        openId = openIdLocal;
    }
    //alert(openId);

    getDataListHttp=function(isRefresh){
        if (isRefresh) {
            pageIndex = 0;
        } else {
            pageIndex++;
        }
        var type='0';
        if(orderVm.activeTop==1){
            type='1'
        }
        else if(orderVm.activeTop==2){
            type='2'
        }
        var param="type="+type+"&pageIndex="+pageIndex+"&pageSize="+pageSize+"&openId="+openId;
        _getHttpsData('/lyPay/orderList',param,
           function(res){
            if(res.status){
                var resData=res.data==undefined ? {}:res.data;
                if (isRefresh) {
                    orderVm.refreshData(resData.records==undefined ? []:resData.records);
                } else {
                    orderVm.appendData(resData.records==undefined ? []:resData.records);
                }
               }else{
                   vant.Toast.fail(res.msg);
               }
           },
           function(err){
                vant.Toast.fail("网络异常"+err.readyState+":"+err.statusText+"("+err.status+")");
                orderVm.loading = false;
                orderVm.finished = true;
           }
       );
    }


    orderVm = new Vue({
        el:'#order_id',
        data:{
            activeTop:0,
            loading: false,
            finished: false,
            refreshing: false,
            dataIsNull:false,
            orderList:[]
        },
        methods:{
            tabBeforeChange:function(position){
                //alert(position);
                this.activeTop=position;
                this.onRefresh();
                return true;
            },
            showStatusName:function(orderItem){
                var sucessStatus = 'TRADE_SUCCESS';
                if(orderItem.hxTime){
                    return '已核销';
                }else if(orderItem.orStatus && orderItem.orStatus == sucessStatus){
                    return '待核销';
                }else{
                    return '未支付';
                }
                /*var obj={
                    "0":"未支付",
                    "1":"待核销",
                    "2":"已结束"
                }
                return obj[status]==undefined ? '已完成':obj[status];*/
            },
            onLoad:function(){
                if(this.refreshing){
                    this.refreshing=false;
                    getDataListHttp(true);
                }else{
                    getDataListHttp(false);
                }
            },
            onRefresh:function(){
                this.refreshing=true;
                // 清空列表数据
                this.finished = false;
                // 重新加载数据
                // 将 loading 设置为 true，表示处于加载状态
                this.loading = true;
                this.onLoad();
            },
            refreshData:function(data){
                //this.dataList=data;
                orderVm.orderList = data;
                this.nextTick(data);
            },
            appendData:function(data){
                //this.dataList=this.dataList.concat(data);
                orderVm.orderList = data;
                this.nextTick(data);
            },
            nextTick:function(data){
                this.loading=false;
                this.finished=data!=undefined && data.length>=pageNum?false:true;
                this.dataIsNull=orderVm.orderList.length==0 ? true:false;
                /*
                this.$nextTick(function(){
                    api.parseTapmode();
                    api.hideProgress();
                })*/
            },
        }
    });
});